//
//  MyBankCard.m
//  DaoZiJinFu
//
//  Created by woker on 16/6/30.
//  Copyright © 2016年 iwoker. All rights reserved.
//

#import "MyBankCard.h"
#import "SettingBankInfo.h"
#import "BindCardTableVC.h"
#import "HotPhoneView.h"

@interface MyBankCard () {
    DZBankInfo *bankInfo;
    HotPhoneView *hotphone;
}

@end

@implementation MyBankCard

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupTitleView:@"我的银行卡"];
    self.view.backgroundColor = BACKGROUND_COLOR;
    [self leftButton:nil];
    _bankListBg.layer.cornerRadius = BTN_RADIUS;
    _bankListBg.layer.masksToBounds = YES;
    _modifyBtn.layer.masksToBounds = YES;
    _modifyBtn.layer.cornerRadius = BTN_RADIUS;
    _modifyBtn.backgroundColor = BLUE_COLOR;
    _cerFlag.layer.cornerRadius = _cerFlag.frame.size.height/2;
    _cerFlag.layer.masksToBounds = YES;
    
    bankInfo = [DZBankInfo mj_objectWithKeyValues:[DZUserInfo.userInfo.banks firstObject]];
    [_bankIcon sd_setImageWithURL:[NSURL URLWithString:bankInfo.bank_logo_path] placeholderImage:[UIImage imageNamed:LOGO_PLACEHOLDER]];
    _bankLab.text = bankInfo.bank_name;
    NSString *bankcard = bankInfo.bank_card_number;
    _cardNum.text = [NSString stringWithFormat:@"%@ **** **** %@",[bankcard substringToIndex:4],[bankcard substringFromIndex:bankcard.length-4]];
    
    if ([bankInfo.certified_status integerValue] == 3 || [bankInfo.certified_status integerValue] == 2) {
        _cerFlag.text = @"已认证";
        [_modifyBtn setTitle:@"更改开户行信息" forState:UIControlStateNormal];
    } else {
        _cerFlag.text = @"未认证";
        [_modifyBtn setTitle:@"更改银行卡信息" forState:UIControlStateNormal];
    }
    
    [_explainLab addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hotPhone)]];
}

- (void)hotPhone {
    NSString *allString = [NSString stringWithFormat:HOTTel];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:allString]];
}

- (IBAction)modifyClick:(id)sender {
    if ([bankInfo.certified_status integerValue] == 1) {
        BindCardTableVC *bindCard = [[BindCardTableVC alloc] init];
        bindCard.editFlag = YES;
        [self.navigationController pushViewController:bindCard animated:YES];
    } else {
        SettingBankInfo *setBankInfo = [[SettingBankInfo alloc] init];
        [self.navigationController pushViewController:setBankInfo animated:YES];
    }
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc]init] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc]init]];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
